const WebpackAliyunOss = require("webpack-aliyun-oss"); // 引入webpack-aliyun-oss
const isDEV = process.env.NODE_ENV === "development";
const Oss = isDEV ? null : require("./oss.config"); // 引入刚刚创建的oss.js文件
const ossPath = "https://pc-gw-website.oss-cn-beijing.aliyuncs.com/";
module.exports = {
  devServer: {
    proxy: {
      "/webapi": {
        target: "http://iot.vnest.net/", //开发
//         target: 'http://www.iot101.com/',//线上
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: {
          "^/webapi": "/",
        },
      },
    },
  },
  publicPath: isDEV ? "./" : ossPath,
  configureWebpack: isDEV
    ? (config) => {}
    : (config) => {
        let webpackAliyunOss = [
          new WebpackAliyunOss({
            from: "./dist/**", // 上传哪个文件或文件夹  可以是字符串或数组
            // dist: "",  // 需要上传到oss上的给定文件目录
            region: Oss.region,
            accessKeyId: Oss.accessKeyId,
            accessKeySecret: Oss.accessKeySecret,
            bucket: Oss.bucket,
            setOssPath: (filePath) => {
              // some operations to filePath
              let index = filePath.lastIndexOf("dist");
              let Path = filePath.substring(index + 4, filePath.length);
              return Path.replace(/\\/g, "/");
            },
            setHeaders: () => {
              // some operations to filePath
              // return false to use default header
              return {
                "Cache-Control": "max-age=31536000",
              };
            },
          }),
        ];
        config.plugins = [...config.plugins, ...webpackAliyunOss];
      },
};